package com.xzy.sms.web.system.utils;

import java.util.List;

import com.google.common.collect.Lists;
import com.xzy.sms.web.system.bean.PermItem;
import com.xzy.sms.web.system.service.PermService;
import com.xzyframework.SpringContextHolder;

/**
 * 权限工具类
 * 
 * @author macong
 * @since 1.0
 * @version 2014-05-14 macong
 */
public class PermUtils {
    
    /** PermService */
    private static PermService permService;
    
    /**
     * 获取所有权限串集合
     * 
     * @return 权限集合数据
     */
    public static List<PermItem> getAllPerm() {
        return getPermService().getAllPerm();
    }
    
    /**
     * 获取所有权限串集合
     * 
     * @return 权限集合数据
     */
    public static List<String> getAllPermStrs() {
        List<String> lst = Lists.newArrayList();
        List<PermItem> permissionItems = getAllPerm();
        for (PermItem permissionItem : permissionItems) {
            String permStr = permissionItem.getPermStr();
            lst.add(permStr);
        }
        return lst;
    }
    
    /**
     * 获取 ConfigService实例
     * 
     * @return ConfigService
     */
    private static PermService getPermService() {
        if (null == permService) {
            return SpringContextHolder.getBean(PermService.class);
        }
        return permService;
    }
}
